package com.alibaba.csp.sentinel.dashboard.rule.zookeeper;

import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity;
import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher;
import com.alibaba.csp.sentinel.datasource.Converter;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ：qilong sun
 * @date ：Created in 2020/7/27 14:06
 * @description：熔断降级
 * @modified By：
 * @version: V1.0$
 */

@Component("authorityRuleZookeeperPublisher")
public class AuthorityRuleZookeeperPublisher implements DynamicRulePublisher<List<AuthorityRuleEntity>> {
    @Autowired
    private CuratorFramework zkClient;
    @Autowired
    private Converter<List<AuthorityRuleEntity>, String> converter;
    /**
     * 规则存储路径
     */
    @Value("${sentinel.rules.authority.path}")
    String rulePath;

    @Override
    public void publish(String app, List<AuthorityRuleEntity> rules) throws Exception {
        ZookeeperConfigUtilEx.publish(app,
                rules,
                rulePath,
                zkClient,
                converter);
    }
}